package xyz.jangle.thread.atomic;

import java.util.concurrent.atomic.AtomicInteger;


/**
 * @author jangle
 * @email 274676957@qq.com
 * 2025年9月12日 下午3:06:05
 */
public class AtomicM {

	/**
	 * 2025年9月12日 下午3:06:05 @author jangle
	 * @param args
	 */
	public static void main(String[] args) {
		AtomicInteger[] vector2 = new AtomicInteger[1000];
		for(int i=0;i<vector2.length;i++) {
			vector2[i] = new AtomicInteger();
		}
		Incrementer2 incrementer2 = new Incrementer2(vector2);
		Decrementer2 decrementer2 = new Decrementer2(vector2);
		
		Thread[] incrementers2 = new Thread[100];
		Thread[] decrementers2 = new Thread[100];
		
		for(int i=0;i<100;i++) {
			incrementers2[i] = new Thread(incrementer2);
			decrementers2[i] = new Thread(decrementer2);
			incrementers2[i].start();
			decrementers2[i].start();
		}
		for (int i = 0; i < 100; i++) {
			try {
				incrementers2[i].join();
				decrementers2[i].join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		for(int i=0;i<vector2.length;i++) {
			if(vector2[i].get()!=0) {
				System.out.println(vector2[i].get());
			}
		}
		
		
	}

}
